package edu.washington.cs.sounddetector.server.api.object;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * <p>
 * A Notification represents a sound event that has been detected by a detector phone.
 * </p>
 * 
 * @author the.dylan.price@gmail.com
 * 
 */
public class Notification
{
    private SoundClass soundClass;
    private String detectorId;
    private List<PeakEvent> peakEvents;

    public Notification()
    {
    }

    /**
     * Construct a new Notification.
     * 
     * @param soundClass
     *            the class of the sound that was detected
     * @param detectorId
     *            the id of the phone that detected the sound
     * @param peakEvents
     *            a list of peak events describing the time and magnitude of peaks in the sound
     */
    public Notification(SoundClass soundClass, String detectorId, List<PeakEvent> peakEvents)
    {
        Validate.notNull(soundClass);
        Validate.notBlank(detectorId);
        Validate.noNullElements(peakEvents);
        this.soundClass = soundClass;
        this.detectorId = detectorId;
        this.peakEvents = peakEvents;
    }

    /**
     * @param soundClass
     *            the soundClass to set
     */
    public void setSoundClass(SoundClass soundClass)
    {
        this.soundClass = soundClass;
    }

    /**
     * @param detectorId
     *            the detectorId to set
     */
    public void setDetectorId(String detectorId)
    {
        this.detectorId = detectorId;
    }

    /**
     * @param peakEvents
     *            the peakEvents to set
     */
    public void setPeakEvents(List<PeakEvent> peakEvents)
    {
        this.peakEvents = peakEvents;
    }

    /**
     * @return the soundClass
     */
    public SoundClass getSoundClass()
    {
        return soundClass;
    }

    public String getDetectorId()
    {
        return detectorId;
    }

    /**
     * @return the peakEvents as a new list
     */
    public List<PeakEvent> getPeakEvents()
    {
        return new ArrayList<PeakEvent>(peakEvents);
    }

    public String toString()
    {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
                .append("soundClass", soundClass).append("detectorId", detectorId)
                .append("peakEvents", peakEvents).toString();
    }
}
